package com.fuqi.android.zhongcai.base.view.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.request.api.ChangePwdApi;
import com.fuqi.android.zhongcai.base.request.result.ChangePwdResult;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.framework.network.http.RequestManager;

import butterknife.Bind;
import butterknife.OnClick;


public class ForgetPassTwoActivity extends BaseActivity {

    @Bind(R.id.et_forgetpass_newpass)
    EditText et_forgetpass_newpass;
    @Bind(R.id.et_forgetpass_replypass)
    EditText et_forgetpass_replypass;
    @Bind(R.id.forgetpassok)
    Button forgetpassok;

    private String et_forgetpass_newpassstr,et_forgetpass_replypassstr ;
    //前面接收到的phone 验证码
    private String phone,voercode;

    @OnClick({ R.id.forgetpassok })
    public void onBtnClick(View view) {
        switch (view.getId()){
            case R.id.forgetpassok:
                et_forgetpass_newpassstr     =  et_forgetpass_newpass.getText().toString().trim();
                et_forgetpass_replypassstr   =  et_forgetpass_replypass.getText().toString().trim();

                if(TextUtils.isEmpty(et_forgetpass_newpassstr)){
                    //此处可以加一个手机号码的验证
                    ActivityUtils.toast("请输入新密码");
                    break;
                }else if(TextUtils.isEmpty(et_forgetpass_replypassstr)){
                    ActivityUtils.toast("请输入确认密码");
                    break;
                }else if(!et_forgetpass_newpassstr.equals(et_forgetpass_replypassstr)){
                    ActivityUtils.toast("两次密码输入的不一致，请重新输入");
                    break;
                }else {
                    RequestManager.getInstance().call(new ChangePwdApi(new ChangePwdApi.ChangePwdParams(getIntent().getStringExtra("phone"),et_forgetpass_newpassstr), respChangePwdListener, errorListener));
                }

                break;
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleBar.setTitle("修改密码");
        phone=getIntent().getStringExtra("phone");
        voercode=getIntent().getStringExtra("vercode");
    }


    Response.Listener<ChangePwdResult> respChangePwdListener = new Response.Listener<ChangePwdResult>() {

        @Override
        public void onResponse(ChangePwdResult response) {

            ActivityUtils.toast("修改密码成功");
            finish();

        }
    };


    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());
        }
    };



    @Override
    public void initView() {

    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_forgetpasstwo;
    }
}
